package com.hengxinguotong.hxgtwygsp.ui.main.Text;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.hengxinguotong.hxgtwygsp.R;
import com.hengxinguotong.hxgtwygsp.model.Rule;
import com.hengxinguotong.hxgtwygsp.ui.base.BaseFragment;
import com.hengxinguotong.hxgtwygsp.ui.main.RuleNoticeAdapter;
import com.hengxinguotong.hxgtwygsp.ui.readFile.FileDisplayActivity;
import com.hengxinguotong.hxgtwygsp.ui.regulation.NoticeAndRuleData;
import com.hengxinguotong.hxgtwygsp.ui.regulation.RegulationActivity;
import com.hengxinguotong.hxgtwygsp.utils.CommUtil;

import java.io.File;
import java.util.ArrayList;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

public class TextFragment extends BaseFragment implements TextContract.IView {

    @Inject
    TextPresenter mPresenter;
    @BindView(R.id.ll_law)
    LinearLayout mLlLaw;
    @BindView(R.id.rv_law)
    RecyclerView mRvLaw;
    @BindView(R.id.ll_policy)
    LinearLayout mLlPolicy;
    @BindView(R.id.rv_policy)
    RecyclerView mRvPolicy;
    @BindView(R.id.ll_convenient_guide)
    LinearLayout mLlConvenientGuide;
    @BindView(R.id.rv_guide)
    RecyclerView mRvGuide;

    public RuleNoticeAdapter mLawAdapter, mPolicyAdapter,mGuideAdapter;
    public ArrayList<Rule> mLawList, mPolicyList,mGuideList;

    @Inject
    public TextFragment() {
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mPresenter.bindView(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mPresenter.dropView();
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_text;
    }

    @Override
    public void init() {

        mLawList = NoticeAndRuleData.getLawHeadList();
        mLawAdapter = new RuleNoticeAdapter(R.layout.item_rule_notice,mLawList);
        mRvLaw.setLayoutManager(new LinearLayoutManager(getContext()));
        mRvLaw.setAdapter(mLawAdapter);

        mPolicyList = NoticeAndRuleData.getPolicyHeadList();
        mPolicyAdapter = new RuleNoticeAdapter(R.layout.item_rule_notice,mPolicyList);
        mRvPolicy.setLayoutManager(new LinearLayoutManager(getContext()));
        mRvPolicy.setAdapter(mPolicyAdapter);

        mGuideList = NoticeAndRuleData.getGuideHeadList();
        mGuideAdapter = new RuleNoticeAdapter(R.layout.item_rule_notice,mGuideList);
        mRvGuide.setLayoutManager(new LinearLayoutManager(getContext()));
        mRvGuide.setAdapter(mGuideAdapter);

        mLawAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Rule rule = mLawList.get(position);
                FileDisplayActivity.show(getContext(), rule.getTitle(), CommUtil.getDataDir(getContext()) + File.separator + rule.getFileName());
            }
        });

        mPolicyAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Rule rule = mPolicyList.get(position);
                FileDisplayActivity.show(getContext(), rule.getTitle(), CommUtil.getDataDir(getContext()) + File.separator + rule.getFileName());
            }
        });

        mGuideAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Rule rule = mGuideList.get(position);
                FileDisplayActivity.show(getContext(), rule.getTitle(), CommUtil.getDataDir(getContext()) + File.separator + rule.getFileName());
            }
        });
    }

    @OnClick({R.id.ll_policy, R.id.ll_law,R.id.ll_convenient_guide})
    public void onClickTab(View v) {
        switch (v.getId()) {
            case R.id.ll_law:
                Intent intent = new Intent(getContext(), RegulationActivity.class);
                intent.putExtra("position",2);
                startActivity(intent);
                break;
            case R.id.ll_policy:
                intent = new Intent(getContext(), RegulationActivity.class);
                intent.putExtra("position",3);
                startActivity(intent);
                break;
            case R.id.ll_convenient_guide:
                intent = new Intent(getContext(), RegulationActivity.class);
                intent.putExtra("position",4);
                startActivity(intent);
                break;
        }

    }


    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        if (isVisibleToUser) {

        } else {

        }
    }


}
